<!DOCTYPE html>
<html>

<head>
	<!-- 页面meta -->
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">

	<title>用户详情</title>

	<!-- Tell the browser to be responsive to screen width -->
	<meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

	<link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="../plugins/ionicons/css/ionicons.min.css">
	<link rel="stylesheet" href="../plugins/iCheck/square/blue.css">
	<link rel="stylesheet" href="../plugins/morris/morris.css">
	<link rel="stylesheet" href="../plugins/jvectormap/jquery-jvectormap-1.2.2.css">
	<link rel="stylesheet" href="../plugins/datepicker/datepicker3.css">
	<link rel="stylesheet" href="../plugins/daterangepicker/daterangepicker.css">
	<link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
	<link rel="stylesheet" href="../plugins/datatables/dataTables.bootstrap.css">
	<link rel="stylesheet" href="../plugins/treeTable/jquery.treetable.css">
	<link rel="stylesheet" href="../plugins/treeTable/jquery.treetable.theme.default.css">
	<link rel="stylesheet" href="../plugins/select2/select2.css">
	<link rel="stylesheet" href="../plugins/colorpicker/bootstrap-colorpicker.min.css">
	<link rel="stylesheet" href="../plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
	<link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
	<link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
	<link rel="stylesheet" href="../css/style.css">
	<link rel="stylesheet" href="../plugins/ionslider/ion.rangeSlider.css">
	<link rel="stylesheet" href="../plugins/ionslider/ion.rangeSlider.skinNice.css">
	<link rel="stylesheet" href="../plugins/bootstrap-slider/slider.css">
	<link rel="stylesheet" href="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
	<link rel="stylesheet" href="../css/user-desc.css" />
	<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
	<script src="../js/jwt-decode.js"></script>
</head>

<body class="hold-transition skin-purple sidebar-mini">

	<div class="wrapper" style="overflow-y: hidden;">

		<!-- 页面头部 -->
		<header class="main-header">

			<!-- Logo -->
			<a href="common-index.html" class="logo">
				<!-- 侧边栏迷你logo，尺寸为50x50像素 -->
				<span class="logo-mini"><b>电子钱包</b></span>
				<!-- 常规状态和移动设备的logo -->
				<span class="logo-lg"><b>电子钱包</b>后台管理</span>
			</a>

			<!-- 头部导航栏：样式可以在header.less中找到 -->
			<nav class="navbar navbar-static-top">
				<!-- 侧边栏切换按钮 -->
				<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
					<span class="sr-only">Toggle navigation</span>
				</a>

				<div class="navbar-custom-menu">
					<ul class="nav navbar-nav">

						<li class="dropdown user user-menu">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								<img src="" class="user-image all-avatar-image">
								<span class="hidden-xs employee-name"></span>
							</a>

							<ul class="dropdown-menu">
								<!-- 用户图片 -->
								<li class="user-header">
									<img src="" class="img-circle all-avatar-image">

									<p class="employee-name"></p>
								</li>

								<li class="user-footer">
									<div class="pull-left">
										<a href="employee-info.html" class="btn btn-default btn-flat">修改信息</a>
									</div>
									<div class="pull-right">
										<a href="javascript:void(0);" class="btn btn-default btn-flat"
											id="logoutBtn">退出账号</a>
									</div>
								</li>
							</ul>
						</li>

					</ul>
				</div>
			</nav>
		</header>
		<!-- 页面头部 /-->

		<!-- 导航侧栏 -->
		<aside class="main-sidebar">
			<!-- 侧边栏：样式可以在sidebar.less中找到 -->
			<section class="sidebar">
				<!-- 侧边栏用户面板 -->
				<div class="user-panel">
					<div class="pull-left image">
						<img src="" class="img-circle all-avatar-image">
					</div>
					<div class="pull-left info">
						<p class="employee-name"></p>
						<a href="#"><i class="fa fa-circle text-success"></i> 在线</a>
					</div>
				</div>

				<ul class="sidebar-menu">
					<li class="header">菜单</li>

					<li id="admin-index"><a href="common-index.html"><i class="fa fa-dashboard"></i> <span>首页</span></a>
					</li>

					<!-- 菜单 -->

					<li class="treeview">
						<a href="#">
							<i class="fa fa-folder"></i>
							<span>系统管理</span>
							<span class="pull-right-container">
								<i class="fa fa-angle-left pull-right"></i>
							</span>
						</a>
						<ul class="treeview-menu">

							<li id="admin-role-manage">
								<a href="role-list.html">
									<i class="fa fa-circle-o"></i> 角色管理
								</a>
							</li>

							<li id="admin-datalist">
								<a href="employee-list.html">
									<i class="fa fa-circle-o"></i> 员工管理
								</a>
							</li>

							<li id="admin-user-manage">
								<a href="user-list.html">
									<i class="fa fa-circle-o"></i> 用户管理
								</a>
							</li>

							<li id="admin-profile">
								<a href="employee-info.html">
									<i class="fa fa-circle-o"></i> 个人中心
								</a>
							</li>

						</ul>
					</li>



					<li class="treeview">
						<a href="#">
							<i class="fa fa-pie-chart"></i> <span>业务管理</span>
							<span class="pull-right-container">
								<i class="fa fa-angle-left pull-right"></i>
							</span>
						</a>
						<ul class="treeview-menu">

							<li id="history-list">
								<a href="history-list.html">
									<i class="fa fa-circle-o"></i> 历史记录管理
								</a>
							</li>

						</ul>
					</li>

				</ul>
			</section>

		</aside>
		<!-- 导航侧栏 /-->

		<!-- 内容区域 -->
		<!-- @@master = admin-layout.html-->
		<!-- @@block = content -->

		<div class="content-wrapper">

			<!-- 内容头部 -->
			<section class="content-header">
				<h1>
					用户管理
					<small>用户详情</small>
				</h1>
				<ol class="breadcrumb">
					<li><a href="#"><i class="fa fa-dashboard"></i>用户管理</a></li>
					<li><a href="#">用户管理</a></li>
					<li class="active">用户详情</li>
				</ol>
			</section>
			<!-- 内容头部 /-->

			<!-- 正文区域 -->
			<section class="content">

				<div class="box box-primary col-sm-12">
					<div class="box-header with-border col-md-12 col-lg-12 col-sm-12">

						<div class="box-userinfo col-md-3 col-sm-10 col-lg-3">
							<h2>个人信息</h2>
							<ul id="userinfo_desc">
							</ul>
						</div>

						<div class="box-userinfo-right col-lg-8 col-md-12 col-sm-10 from-style">
							<h2>绑定银行卡</h2>
							<div class="box-userinfo-right-form">

								<div class="box-userinfo-right-form-base card-box">
									<li class="col-sm-12 card-title" id="card-bind">
										<span class="col-sm-6">卡号</span>
										<span class="col-sm-3">类型</span>
										<span class="col-sm-3">绑卡时间</span>
									</li>
								</div>

							</div>


						</div>
						<div class="box-userinfo-right col-lg-8 col-md-12 col-sm-10"
							style="margin-top: 30px; padding: 15px;display: flex; justify-content: center; align-items: center;">
							<button class="box-userinfo-right-btn-save" id="updae-password-button" type="button"
								onclick="history.back(-1);" style="display: inline-block;margin: 0 auto;">返回</button>
						</div>

					</div>


				</div>


			</section>
			<!-- 正文区域 /-->

		</div>
		<!-- @@close -->
		<!-- 内容区域 /-->

		<!-- 底部导航 -->
		<footer class="main-footer">
			<strong>Copyright &copy; <a href="">电子钱包</a>.</strong> All rights reserved.
		</footer>
		<!-- 底部导航 /-->

	</div>

	<script type="text/javascript">

		// 顶部与侧边栏信息渲染,注销按钮
		$(document).ready(function () {
			var token = localStorage.getItem('token');
			var longToken = localStorage.getItem('longToken');

			// 获取注销按钮
			var logoutBtn = $("#logoutBtn");

			// 为注销按钮添加点击事件
			logoutBtn.click(function () {
				// 清除本地存储的 token 和 longToken
				localStorage.removeItem('token');
				localStorage.removeItem('longToken');
				// 跳转到登录
				window.location.href = 'employee-login.html';
			});

			if (token && longToken) {
				var decoded = jwt_decode(longToken);
				var userId = decoded.userId;

				getInfo(userId, token, longToken);
				getUserInfo(token, longToken);
			} else {
				// 跳转到登录页面
				window.location.href = 'employee-login.html';
			}
		});

		// 获取个人数据，渲染侧边栏和头部
		function getInfo(userId, token, longToken) {
			var url = 'http://localhost:8080/employee/findByIdController?userId=' + userId;

			if (token && longToken) {
				url += '&token=' + token + '&longToken=' + longToken;
			}

			// 发送 AJAX 请求获取数据
			$.ajax({
				url: url,
				method: 'get',
				success: function (result) {

					if (result.code === 200) {
						var datas = result.datas;
						var imageUrl = "http://localhost:8080/" + datas.imageAddress;

						var imgs = document.querySelectorAll('img.all-avatar-image');
						imgs.forEach(function (img) {
							img.src = imageUrl;
						});

						var elements = document.querySelectorAll('.employee-name');
						elements.forEach(function (el) {
							el.innerHTML = datas.userName;
						});

					} else if (result.code === 6000 || result.code === 4000) {
						// 跳转到登录
						window.location.href = 'employee-login.html';
					} else {
						alert("获取数据失败");
					}

				},
				error: function (xhr, status, error) {
					console.log("请求失败");
				}
			});
		}


		// 根据userId获取个人信息去渲染个人信息
		function getUserInfo(token, longToken) {
			var urlParams = new URLSearchParams(window.location.search);
			var userId = urlParams.get('userId');

			if (userId != null && !isNaN(parseInt(userId))) {
				$.ajax({
					url: 'http://localhost:8080/user/findByIdController?userId=' + userId + "&token=" + token + '&longToken=' + longToken,
					type: 'GET',
					success: function (result) {
						// 处理获取到的数据
						if (result.code == 200) {
							var datas = result.datas;
							var ul = document.getElementById("userinfo_desc");
							var userInfo = "";

							userInfo += '<li><span class="fa fa-lock" aria-hidden="true">&nbsp;账号</span><span>' + datas.loginAccount + '</span></li>';
							userInfo += '<li><span class="fa fa-list-alt" aria-hidden="true">&nbsp;用户编号</span><span>' + datas.userNumber + '</span></li>';
							userInfo += '<li><span class="fa fa-user" aria-hidden="true">&nbsp;姓名</span><span>' + datas.userName + '</span></li>';
							userInfo += '<li><span class="fa fa-pencil-square-o" aria-hidden="true">&nbsp;英文名</span><span>' + datas.englishName + '</span></li>';
							userInfo += '<li><span class="fa fa-phone" aria-hidden="true">&nbsp;手机号码</span><span>' + datas.phone + '</span></li>';
							// userInfo += '<li data-toggle="popover" data-content="' + datas.email + '"><span class="fa fa-envelope" aria-hidden="true">&nbsp;邮箱</span><span>' + datas.email + '</span></li>';

							var email = datas.email;
							var emailContent = '';
							var emailSpan = document.createElement('span');
							emailSpan.style.visibility = 'hidden';
							emailSpan.style.position = 'absolute';
							emailSpan.style.whiteSpace = 'nowrap';
							emailSpan.style.fontSize = '14px'; // 根据实际情况设置字体大小
							emailSpan.style.fontFamily = 'Arial'; // 根据实际情况设置字体
							emailSpan.innerHTML = email;
							document.body.appendChild(emailSpan);
							if (emailSpan.offsetWidth > 160) {
								emailContent = email;
							}
							document.body.removeChild(emailSpan);
							var emailHtml = '<li';
							if (emailContent) {
								emailHtml += ' data-toggle="popover" data-content="' + emailContent + '"';
							}
							emailHtml += '><span class="fa fa-envelope" aria-hidden="true">&nbsp;邮箱</span><span style="width: 150px;">' + email + '</span></li>';
							userInfo += emailHtml;


							userInfo += '<li ><span class="fa fa-calendar" aria-hidden="true">&nbsp;出生日期</span><span>' + formatDate(datas.borndate) + '</span></li>';
							userInfo += '<li><span class="fa fa-venus-mars" aria-hidden="true">&nbsp;性别</span><span>' + datas.gender + '</span></li>';
							// userInfo += '<li data-toggle="popover" data-content="' + datas.homeAddress + '"><span class="fa fa-building" aria-hidden="true">&nbsp;家庭地址</span><span>' + datas.homeAddress + '</span></li>';

							var homeAddress = datas.homeAddress;
							var homeAddressContent = '';
							var homeAddressSpan = document.createElement('span');
							homeAddressSpan.style.visibility = 'hidden';
							homeAddressSpan.style.position = 'absolute';
							homeAddressSpan.style.whiteSpace = 'nowrap';
							homeAddressSpan.style.fontSize = '14px'; // 根据实际情况设置字体大小
							homeAddressSpan.style.fontFamily = 'Arial'; // 根据实际情况设置字体
							homeAddressSpan.innerHTML = homeAddress;
							document.body.appendChild(homeAddressSpan);
							if (homeAddressSpan.offsetWidth > 160) { // 如果宽度超过指定值
								homeAddressContent = homeAddress;
							}
							document.body.removeChild(homeAddressSpan);
							var homeAddressHtml = '<li';
							if (homeAddressContent) {
								homeAddressHtml += ' data-toggle="popover" data-content="' + homeAddressContent + '"';
							}

							homeAddressHtml += '><span class="fa fa-building" aria-hidden="true">&nbsp;家庭地址</span><span>' + homeAddress + '</span></li>';
							userInfo += homeAddressHtml;

							// userInfo += '<li data-toggle="popover" data-content="' + datas.companyAddress + '"><span class="fa fa-building-o" aria-hidden="true">&nbsp;公司地址</span><span>' + datas.companyAddress + '</span></li>';

							var companyAddress = datas.companyAddress;
							var companyAddressContent = '';
							var companyAddressSpan = document.createElement('span');
							companyAddressSpan.style.visibility = 'hidden';
							companyAddressSpan.style.position = 'absolute';
							companyAddressSpan.style.whiteSpace = 'nowrap';
							companyAddressSpan.style.fontSize = '14px'; // 根据实际情况设置字体大小
							companyAddressSpan.style.fontFamily = 'Arial'; // 根据实际情况设置字体
							companyAddressSpan.innerHTML = companyAddress;
							document.body.appendChild(companyAddressSpan);
							if (companyAddressSpan.offsetWidth > 160) { // 如果宽度超过指定值
								companyAddressContent = companyAddress;
							}
							document.body.removeChild(companyAddressSpan);
							var companyAddressHtml = '<li';
							if (companyAddressContent) {
								companyAddressHtml += ' data-toggle="popover" data-content="' + companyAddressContent + '"';
							}
							companyAddressHtml += '><span class="fa fa-building-o" aria-hidden="true">&nbsp;公司地址</span><span>' + companyAddress + '</span></li>';
							userInfo += companyAddressHtml;

							ul.innerHTML = userInfo;

							var userNumber = datas.userNumber;
							getCardBind(userNumber, token, longToken);

							$(function () {
								$('[data-toggle="popover"]').popover({
									trigger: 'hover', // 鼠标移入时触发
									html: true // 允许使用 HTML 内容
								})
							})
						} else if (result.code == 4000) {
							// 跳转到登录页面
							window.location.href = 'employee-login.html';
						} else {
							window.location.href = 'common-404.html';
						}
					},
					error: function (xhr, status, error) {
						console.log("请求失败");
					}
				});
			} else {
				window.location.href = 'common-404.html';
			}
		}

		// 根据userNumber渲染绑定的银行卡
		function getCardBind(userNumber, token, longToken) {
			$.ajax({
				url: 'http://localhost:8080/user/queryBindAccountListController?userNumber=' + userNumber + "&token=" + token + '&longToken=' + longToken,
				type: 'GET',
				success: function (result) {
					// 处理获取到的数据
					if (result.code == 200) {

						var cardData = result.datas
						var li = document.getElementById("card-bind");

						if (cardData != null && cardData.length > 0) {
							// 使用for循环遍历数组中的每个元素
							for (var i = 0; i < cardData.length; i++) {
								// 创建新的li元素
								var newLi = document.createElement("li");
								newLi.setAttribute("class", "col-sm-12");

								// 创建三个新的span元素
								var cardNumber = document.createElement("span");
								cardNumber.setAttribute("class", "col-sm-6");
								var accountNumber = cardData[i].accountNumber;
								var len = accountNumber.length;
								var lastFour = accountNumber.substring(len - 4, len); // 获取银行卡号的后四位
								var hideStr = "**** **** **** "; // 隐藏的字符串
								cardNumber.innerHTML = hideStr + lastFour;

								var cardType = document.createElement("span");
								cardType.setAttribute("class", "col-sm-3");
								cardType.innerHTML = cardData[i].accountType;

								var bindTime = document.createElement("span");
								bindTime.setAttribute("class", "col-sm-3");
								bindTime.innerHTML = formatDate(cardData[i].bindingTime);

								// 将三个span元素添加到新的li元素中
								newLi.appendChild(cardNumber);
								newLi.appendChild(cardType);
								newLi.appendChild(bindTime);

								// 将新的li元素添加到id为"card-bind"的li元素后面
								li.parentNode.insertBefore(newLi, li.nextSibling);
							}
						} else {
							// 隐藏id为"card-bind"的元素
							li.style.display = "none";
							// 无卡
							li.insertAdjacentHTML("afterend", '<div action="" class="box-userinfo-right-form-update from-style"><div class="col-sm-12 nothing">暂无绑定银行卡</div></div>');

						}

					} else if (result.code == 4000) {
						// 跳转到登录页面
						window.location.href = 'employee-login.html';
					} else {
						window.location.href = 'common-404.html';
					}
				},
				error: function (xhr, status, error) {
					console.log("请求失败");
				}
			});
		}



		// 格式化日期
		function formatDate(date) {
			var formattedDate = new Date(date);
			var year = formattedDate.getFullYear();
			var month = ("0" + (formattedDate.getMonth() + 1)).slice(-2);
			var day = ("0" + formattedDate.getDate()).slice(-2);
			return year + "-" + month + "-" + day;
		}


	</script>


	<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
	<script src="../plugins/jQueryUI/jquery-ui.min.js"></script>
	<script>
		$.widget.bridge('uibutton', $.ui.button);
	</script>
	<script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
	<script src="../plugins/raphael/raphael-min.js"></script>
	<script src="../plugins/morris/morris.min.js"></script>
	<script src="../plugins/sparkline/jquery.sparkline.min.js"></script>
	<script src="../plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
	<script src="../plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
	<script src="../plugins/knob/jquery.knob.js"></script>
	<script src="../plugins/daterangepicker/moment.min.js"></script>
	<script src="../plugins/daterangepicker/daterangepicker.js"></script>
	<script src="../plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
	<script src="../plugins/datepicker/bootstrap-datepicker.js"></script>
	<script src="../plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
	<script src="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
	<script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script>
	<script src="../plugins/fastclick/fastclick.js"></script>
	<script src="../plugins/iCheck/icheck.min.js"></script>
	<script src="../plugins/adminLTE/js/app.min.js"></script>
	<script src="../plugins/treeTable/jquery.treetable.js"></script>
	<script src="../plugins/select2/select2.full.min.js"></script>
	<script src="../plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
	<script src="../plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
	<script src="../plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
	<script src="../plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
	<script src="../plugins/bootstrap-markdown/js/markdown.js"></script>
	<script src="../plugins/bootstrap-markdown/js/to-markdown.js"></script>
	<script src="../plugins/ckeditor/ckeditor.js"></script>
	<script src="../plugins/input-mask/jquery.inputmask.js"></script>
	<script src="../plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
	<script src="../plugins/input-mask/jquery.inputmask.extensions.js"></script>
	<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
	<script src="../plugins/datatables/dataTables.bootstrap.min.js"></script>
	<script src="../plugins/chartjs/Chart.min.js"></script>
	<script src="../plugins/flot/jquery.flot.min.js"></script>
	<script src="../plugins/flot/jquery.flot.resize.min.js"></script>
	<script src="../plugins/flot/jquery.flot.pie.min.js"></script>
	<script src="../plugins/flot/jquery.flot.categories.min.js"></script>
	<script src="../plugins/ionslider/ion.rangeSlider.min.js"></script>
	<script src="../plugins/bootstrap-slider/bootstrap-slider.js"></script>
	<script src="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
	<script src="../plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
	<script>
		$(document).ready(function () {
			// 选择框
			$(".select2").select2();

			// WYSIHTML5编辑器
			$(".textarea").wysihtml5({
				locale: 'zh-CN'
			});
		});


		// 设置激活菜单
		function setSidebarActive(tagUri) {
			var liObj = $("#" + tagUri);
			if (liObj.length > 0) {
				liObj.parent().parent().addClass("active");
				liObj.addClass("active");
			}
		}


		$(document).ready(function () {
			setSidebarActive("admin-user-manage");
		});

	</script>
</body>

</html>